<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>张院百货商城-登录</title>
    <link rel="stylesheet" th:href="@{mall/css/common.css}">
    <link rel="stylesheet" th:href="@{mall/styles/login.css}">
    <link rel="stylesheet" th:href="@{mall/styles/header.css}">
    <link rel="stylesheet" th:href="@{/admin/plugins/sweetalert/sweetalert.css}" />
</head>

<body>
    <div class="top center">
        <div class="logo center">
            <a href="./index.html" target="_blank"><img src="mall/image/login-logo-2.png" alt=""></a>
        </div>
    </div>
    <div class="form center">
        <div class="login">
            <div class="login_center">
                <div class="login_top">
                    <div class="left fl">用户登录</div>
                    <div class="right fr">您还不是我们的用户？<a href="register.html" target="_self">立即注册</a></div>
                    <div class="clear"></div>
                    <div class="under-line center"></div>
                </div>
                <form id="loginForm" onsubmit="return false;" action="##">
                    <div class="login_main center">
                        <div class="login-info">手机号:&nbsp;<input class="login-info-input" type="text" name="loginName"
                                id="loginName" placeholder="请输入你的手机号" />
                        </div>
                        <div class="login-info">密&nbsp;&nbsp;&nbsp;&nbsp;码:&nbsp;<input class="login-info-input"
                                id="password" type="password" name="password" placeholder="请输入你的密码" /></div>
                        <div class="login-info">
                            验证码:&nbsp;
                            <input class="login-info-input verify-code" type="text" name="verifyCode"
                                placeholder="请输入验证码" id="verifyCode" />
                            <img alt="单击图片刷新！" style="top: 14px;position: relative;" th:src="@{/common/mall/kaptcha}"
                                onclick="this.src='/common/mall/kaptcha?d='+new Date()*1">
                        </div>
                    </div>
                    <div class="login_submit">
                        <input class="submit" type="submit" onclick="login()" value="立即登录">
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
<!-- jQuery -->
<script th:src="@{/admin/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/admin/dist/js/public.js}"></script>
<script th:src="@{/admin/plugins/sweetalert/sweetalert.min.js}"></script>
<script th:src="@{/mall/js/axios.js}"></script>
<script type="text/javascript">
    function login() {
        var loginName = $("#loginName").val();
        if (!validPhoneNumber(loginName)) {
            swal('请输入正确的登录名(即手机号)', {
                icon: "error",
            });
            return false;
        }
        var password = $("#password").val();
        if (!validPassword(password)) {
            swal('请输入正确的密码格式(6-20位字符和数字组合)', {
                icon: "error",
            });
            return false;
        }
        var verifyCode = $("#verifyCode").val();
        if (!validLength(verifyCode, 7)) {
            swal('请输入正确的验证码', {
                icon: "error",
            });
            return false;
        }
        //验证
        var params = $("#loginForm").serialize();
        var url = '/login';

        axios.post(url, params)
            .then(res => {
                if (res.status == 200) {
                    window.location.href = '/index';
                } else {
                    swal(res.data, {
                        icon: "error",
                    });
                }
            })
            .catch(err => {
                swal("操作失败", {
                    icon: "error",
                });
            });

    }
</script>

</html>